package com.csair.youth.dao.impl.hibernate3;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.csair.youth.database.RolePermission;

/**
 * Impl:auto created by daobuilder1.1.1 
 * @version 1.0
 * @author daobuilder@csair.com
 */
public class RolePermissionDaoImpl extends com.csair.youth.dao.impl.hibernate3.base.RolePermissionDaoImplBase{
	private static final String FIND_BY_ROLE_ID_HQL = "from "+RolePermission.REF+" a where a."+RolePermission.PROP_ROLE_ID+"=:roleId";
	private static final String FIND_BY_PERMISSION_ID_HQL = "from "+RolePermission.REF+" a where a."+RolePermission.PROP_PERMISSION_ID+"=:permissionId";
	private static final String DELETE_ROLE_PERMISSIONS_HQL = "delete from "+RolePermission.REF+" a where a."+RolePermission.PROP_ROLE_ID+"=:roleId";
	
	public List findByRoleId(String roleId){
		Map param = new HashMap();
		param.put("roleId", roleId);
		return this.getGenericDao().find(FIND_BY_ROLE_ID_HQL, param, null);
	}
	
	public List findByPermissionId(String permissionId){
		Map param = new HashMap();
		param.put("permissionId", permissionId);
		return this.getGenericDao().find(FIND_BY_PERMISSION_ID_HQL, param, null);
	}
	
	public void deleteRoleOldPermissions(String roleId){
		Map param = new HashMap();
		param.put("roleId", roleId);
		this.getGenericDao().execute(DELETE_ROLE_PERMISSIONS_HQL, param);
	}
}